package 相差不超过k的最多数;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        int i = 0, j = 0, res = 0;
        while (j < n) {
            while (j < n && a[j] - a[i] <= k) {
                j++;
            }
            res = Math.max(res, j - i);
            i++;
        }
        System.out.println(res);
    }
}
